<?php namespace models;
/**
 * This code is property of Piotr Poradzisz. Do not distribute under threat of legal consequences.
 * All rights reserved.
 * Все права защищены.
 * Alle Rechte vorbehalten.
 * Todos los derechos reservados.
 * Wszelkie prawa zastrzeżone.
 *                  جميع الحقوق محفوظة
 * 保留所有权利
 * すべての著作権
 * @author Piotr Poradzisz
 * email: piotr.poradzisz@gmail.com
 * tel.: +48668027020
 */

class Search extends Field{

    public static function getSearchFields($menu){
        $mysql = new Mysql();
        $from = $_SESSION['query']['from'];
        $fields = self::getFields($menu, 'f.searchRights');
        $return = array();
        foreach($fields as $key => $value){
            if($value['fieldTag'] != 'select' and $value['fieldType'] != 'radio'){
                array_push($return, $fields[$key]);
            }
            else{
                $mysql = new Mysql();
                if($value['tableName'] == $from and $value['name'] == 'parent'){
                   $query = "SELECT t1.id, t1.parent, CONCAT_WS(' -> ',t2.name, t1.name) as name FROM $value[tableName] t1 JOIN $value[tableName] t2 ON t1.parent = t2.id";
                }
                else{
                    $query = "SELECT id, $value[name] FROM $value[tableName]";
                }
                $value['options'] = $mysql->getTable($query);
                array_push($return,  $value);
            }
        }
        return $return;
    }
}
?>